package com.imot.config;

/**
 * ClassName: DurationToFormattedStringSerializer
 * Description:
 * date: 2023/11/8 16:04
 *
 * @author imot-jiah.wang
 */
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

public class DurationToFormattedStringSerializer extends JsonSerializer<Long> {
    @Override
    public void serialize(Long durationInMinutes, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        long hours = durationInMinutes / 60;
        long minutes = durationInMinutes % 60;
        String formattedDuration = String.format("%d小时%d分钟", hours, minutes);
        jsonGenerator.writeString(formattedDuration);
    }
}

